// PlgDialog.cpp : implementation file
//

#include "stdafx.h"
#include "Abc.h"
#include "PlgDialog.h"
#include "HookApi.h"
#include "Resource.h"


// CPlgDialog dialog

IMPLEMENT_DYNAMIC(CPlgDialog, CDialog)

CPlgDialog::CPlgDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CPlgDialog::IDD, pParent)
{

}

CPlgDialog::~CPlgDialog()
{
}

void CPlgDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CPlgDialog, CDialog)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_HOOKBUTTON, &CPlgDialog::OnBnClickedHookbutton)
	ON_BN_CLICKED(IDC_READBUTTON, &CPlgDialog::OnBnClickedReadbutton)
	ON_BN_CLICKED(IDC_WRITEBUTTON, &CPlgDialog::OnBnClickedWritebutton)
END_MESSAGE_MAP()


// CPlgDialog message handlers

void CPlgDialog::OnClose()
{
	// TODO: Add your message handler code here and/or call default
	ShowWindow(SW_HIDE);
	//CDialog::OnClose();
}

typedef int (WINAPI __pfnRecv)(SOCKET s, char* buf, int len,  int flags);
int WINAPI MyRecv(DWORD RetAddr,__pfnRecv pfnRecv,SOCKET s, char* buf, int len,  int flags);

int WINAPI MyRecv(DWORD RetAddr,__pfnRecv pfnRecv,SOCKET s, char* buf, int len,  int flags)
{
	return pfnRecv(s,buf,len,flags);
}



void CPlgDialog::OnBnClickedHookbutton()
{
	// TODO: Add your control notification handler code here
	::InstallHookApi("ws2_32.dll","recv",recv);
}

void CPlgDialog::OnBnClickedReadbutton()
{
	// TODO: Add your control notification handler code here
	DWORD address=::GetDlgItemInt(this->m_hWnd,IDC_ADDRESS,NULL,TRUE);
	::SetDlgItemInt(this->m_hWnd,IDC_VALUE,*((byte*)address),TRUE);
}

void CPlgDialog::OnBnClickedWritebutton()
{
	// TODO: Add your control notification handler code here
	DWORD address=::GetDlgItemInt(this->m_hWnd,IDC_ADDRESS,NULL,TRUE);
	*((byte*)address)=::GetDlgItemInt(this->m_hWnd,IDC_VALUE,NULL,TRUE);
}
